﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTOSingTowerMall;

namespace BLSingTowerMall
{
    public class AvailableEventHallProcess
    {
        private DBSingTowerMallEntities cntx = new DBSingTowerMallEntities();

        public IQueryable<AvailableEventHallsDetails> getAvailableEventHalls(string startDateTime, string endDateTime)

        {

            DateTime stDate = Convert.ToDateTime(startDateTime);
            DateTime endDate = Convert.ToDateTime(endDateTime);


            IQueryable<int> allHallIDList = from h in cntx.EventHalls
                                                    select h.HallID;

            IQueryable<int> bookedhallIDList = from hb in cntx.EventHallBookings
                             where (hb.Status == "Approved")
                                && (stDate <=hb.EventStartDateTime )
                                && (endDate >= hb.EventEndDateTime )
                             select hb.HallID;

            IQueryable<AvailableEventHallsDetails> avalaiblehalls =  from s in cntx.EventHalls
                                                            where //h.HallID != bookedhallIDList.
                                                            !bookedhallIDList.Contains(s.HallID)
                                                    select new AvailableEventHallsDetails {
                                                        HallID = s.HallID,
                                                        HallName = s.HallName,
                                                        HallType = s.HallType,
                                                        Capacity = s.Capacity,
                                                        Dimension = ((from b in cntx.Blocks
                                                                      where b.BlockID == s.BlockID
                                                                      select b.Dimension).FirstOrDefault()),
                                                        PricePerDay = ( (from b in cntx.Blocks
                                                                        where b.BlockID == s.BlockID
                                                                        select b.PricePerDay).FirstOrDefault() ),
                                                        Location = ((from b in cntx.Blocks
                                                                     where b.BlockID == s.BlockID
                                                                     select b.Location).FirstOrDefault()),
                                                        Level = ((from b in cntx.Blocks
                                                                  where b.BlockID == s.BlockID
                                                                  select b.Level).FirstOrDefault()),
                                                    };
            return avalaiblehalls;
            

        }
    }
}
